using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLREINKL
    {
        public DataRow Convert2LREINKL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLREINKL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LREMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LREREZART"] = " ".PadRight(1 ); 
         dwReturn["LREREZNR"] = " ".PadRight(10 ); 
         dwReturn["LREREZST"] = " ".PadRight(1 ); 
         dwReturn["LREEKL"] = " ".PadRight(7 ); 
         dwReturn["LREVAR"] = " ".PadRight(2 ); 
         dwReturn["LREWERT1"] = " ".PadRight(15 ); 
         dwReturn["LREWERT2"] = " ".PadRight(15 ); 
         dwReturn["LREWERT3"] = " ".PadRight(15 ); 
         dwReturn["LREWERT4"] = " ".PadRight(15 ); 
         dwReturn["LREWERT5"] = " ".PadRight(15 ); 
         dwReturn["LREWERT6"] = " ".PadRight(15 ); 
         dwReturn["LREWERT7"] = " ".PadRight(15 ); 
         dwReturn["LREWERT8"] = " ".PadRight(15 ); 
         dwReturn["LREFILLER2"] = " ".PadRight(11 ); 
         dwReturn["LREAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LREAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LREAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LRENEUBEN"] = " ".PadRight(8 ); 
         dwReturn["LRENEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLREINKL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLREINKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLREINKL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLREINKL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLREINKL(dwLocal, ITXDBVERSION);
            }
            UpdateLREINKL(dwLocal);
        }
        public void InsertLREINKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LREINKL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLREINKL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LREINKL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LREINKL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LREINKL";
            Return = Result;
            return Return;
        }
        public void DeleteLREINKL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LREINKL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLREINKL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LREINKL SET "
                    +"LREMANDANT= :LREMANDANT,"
                    +"LREREZART= :LREREZART,"
                    +"LREREZNR= :LREREZNR,"
                    +"LREREZST= :LREREZST,"
                    +"LREEKL= :LREEKL,"
                    +"LREVAR= :LREVAR,"
                    +"LREWERT1= :LREWERT1,"
                    +"LREWERT2= :LREWERT2,"
                    +"LREWERT3= :LREWERT3,"
                    +"LREWERT4= :LREWERT4,"
                    +"LREWERT5= :LREWERT5,"
                    +"LREWERT6= :LREWERT6,"
                    +"LREWERT7= :LREWERT7,"
                    +"LREWERT8= :LREWERT8,"
                    +"LREFILLER2= :LREFILLER2,"
                    +"LREAENDZL= :LREAENDZL,"
                    +"LREAENDBEN= :LREAENDBEN,"
                    +"LREAENDDAT= :LREAENDDAT,"
                    +"LRENEUBEN= :LRENEUBEN,"
                    +"LRENEUDAT= :LRENEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LREMANDANT", OracleType.NVarChar).Value = dwData["LREMANDANT"].ToString(); 
          or1.Parameters.Add("LREREZART", OracleType.NVarChar).Value = dwData["LREREZART"].ToString(); 
          or1.Parameters.Add("LREREZNR", OracleType.NVarChar).Value = dwData["LREREZNR"].ToString(); 
          or1.Parameters.Add("LREREZST", OracleType.NVarChar).Value = dwData["LREREZST"].ToString(); 
          or1.Parameters.Add("LREEKL", OracleType.NVarChar).Value = dwData["LREEKL"].ToString(); 
          or1.Parameters.Add("LREVAR", OracleType.NVarChar).Value = dwData["LREVAR"].ToString(); 
          or1.Parameters.Add("LREWERT1", OracleType.NVarChar).Value = dwData["LREWERT1"].ToString(); 
          or1.Parameters.Add("LREWERT2", OracleType.NVarChar).Value = dwData["LREWERT2"].ToString(); 
          or1.Parameters.Add("LREWERT3", OracleType.NVarChar).Value = dwData["LREWERT3"].ToString(); 
          or1.Parameters.Add("LREWERT4", OracleType.NVarChar).Value = dwData["LREWERT4"].ToString(); 
          or1.Parameters.Add("LREWERT5", OracleType.NVarChar).Value = dwData["LREWERT5"].ToString(); 
          or1.Parameters.Add("LREWERT6", OracleType.NVarChar).Value = dwData["LREWERT6"].ToString(); 
          or1.Parameters.Add("LREWERT7", OracleType.NVarChar).Value = dwData["LREWERT7"].ToString(); 
          or1.Parameters.Add("LREWERT8", OracleType.NVarChar).Value = dwData["LREWERT8"].ToString(); 
          or1.Parameters.Add("LREFILLER2", OracleType.NVarChar).Value = dwData["LREFILLER2"].ToString(); 
          or1.Parameters.Add("LREAENDZL", OracleType.NVarChar).Value = dwData["LREAENDZL"].ToString(); 
          or1.Parameters.Add("LREAENDBEN", OracleType.NVarChar).Value = dwData["LREAENDBEN"].ToString(); 
          or1.Parameters.Add("LREAENDDAT", OracleType.NVarChar).Value = dwData["LREAENDDAT"].ToString(); 
          or1.Parameters.Add("LRENEUBEN", OracleType.NVarChar).Value = dwData["LRENEUBEN"].ToString(); 
          or1.Parameters.Add("LRENEUDAT", OracleType.NVarChar).Value = dwData["LRENEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
